package com.rainsoftware.LicenseSystem.utils;

import lombok.Data;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@Data
public class StandardResponse {

    private boolean success;
    private int status;
    private JSONObject dataJson;
    private String message;

    public StandardResponse(boolean success, HttpStatus status, String message) {
        this.success = success;
        this.status = status.value();
        this.message = message;
        this.dataJson = null;
    }

    public StandardResponse(boolean success, int status, String message) {
        this.success = success;
        this.status = status;
        this.message = message;
        this.dataJson = null;
    }

    public StandardResponse(boolean success, HttpStatus status, String message, JSONObject data) {
        this.success = success;
        this.status = status.value();
        this.message = message;
        this.dataJson = data;
    }

    public ResponseEntity<String> build() {
        JSONObject response = new JSONObject();
        response.put("success", success);
        response.put("code", status);
        response.put("message", message);
        if (dataJson == null) {
            dataJson = new JSONObject();
        }
        response.put("data", dataJson);
        return ResponseEntity.status(HttpStatus.OK).body(response.toString());
    }
}